﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using MS.InformationManagement.DAL.DocumentCenter;
using System.Collections.Generic;
using System.Linq;

namespace MS.InformationManagement.Controls._CONTROLTEMPLATES.InformationManagerControls
{
    public partial class DocumentDeliveryLog : UserControl
    {

        #region Fields

        public List<DeliveryTraceabilityEntry> DeliveryLogsEntries {get; set;}

        #endregion

        #region Form Events

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            Pager1.OnPageChanged += new Pager.PageChangeHandler(Pager1_OnPageChanged);
            Pager1.PageIndex = 0;
        }

        protected void Pager1_OnPageChanged(object sender, PageChangeEventArgs e)
        {
            setPager();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack) return;
            setPager();
        }

        #endregion

        #region Private Methods

        private void setPager()
        {
            if (DeliveryLogsEntries == null || DeliveryLogsEntries.Count == 0) return;
            int startingIndex = Pager1.PageIndex * Pager1.PageSize;
            gvLog.DataSource = DeliveryLogsEntries.Skip(startingIndex).Take(Pager1.PageSize);
            gvLog.DataBind();
            Pager1.TotalRecords = DeliveryLogsEntries.Count();
            Pager1.BuildPager();
        }

        #endregion
    }
}
